home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / xconf / xconf.c < prev    next >
C/C++ Source or Header  |  1995-01-16  |  5KB  |  187 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdarg.h>
  4. #include "../misc/misc.h"
  5. #include "xconf.h"
  6. #include "section.h"
  7.  
  8. /* #Specification: strategy
  9.     Each task of the X configurator produce a part of an Xconfig.
  10.     (Some task have other side effect such has creating files and
  11.     symlink). At the end, all parts are merged together in the following
  12.     order.
  13.  
  14.         fonts
  15.         keyboard
  16.         mouse
  17.         screen
  18.         adaptor
  19.  
  20.     The merge goes like this. If a part supply a suboption which redefine
  21.     one supplied by a previous part, then the new part has precedence.
  22.     I don't expect this to happen often but I see a case. Adaptor are
  23.     sometime more restrictive for the operationnal mode. For example
  24.     some 8514 (all ?) board only support a fixed resolution (1024x768)
  25.     beside the standard VGA. So even if the screen have all kind of
  26.     resolution defined, the adaptor configuration will take precedence.
  27.  
  28.     The future will tell if this is true...
  29. */
  30.     
  31. struct XCONFIGS{
  32.     XCONFIG adaptor;
  33.     XCONFIG screen;
  34.     XCONFIG mouse;
  35.     XCONFIG keyboard;
  36.     XCONFIG fonts;
  37. };
  38.  
  39.  
  40. static void xconf_other ()
  41. {
  42.     int done = 0;
  43.     int choice = 0;
  44.     while (!done){
  45.         static char *menuopt[]={
  46.             "See",        "current configuration",
  47.             "Compare",    "Find the difference with",
  48.             " ",        "the current /etc/XF86Config",
  49.             " ",        "(don't change anything)",
  50.         };
  51.         xconf_menu ("The X configurator"
  52.             ,"Other options of xconf\n"
  53.              "      bla\n"
  54.              "      bla"
  55.             ,help_nil
  56.             ,menuopt,choice);
  57.         if (choice == -1){
  58.             done = 1;
  59.         }else{
  60.             switch (choice){
  61.             case 0:
  62.                 // Show current configuration
  63.                 break;
  64.             case 1:
  65.                 // Compare
  66.                 break;
  67.             }
  68.         }
  69.     }
  70. }
  71.  
  72. static char *xconf_formatmenu (
  73.     XCONFIG &xcfg,
  74.     const char *keyw)
  75. {
  76.     const char *val = xcfg.getcomment (keyw);
  77.     char *curval = " -- Not set --";
  78.     char bufval[80];
  79.     if (val != NULL){
  80.         sprintf (bufval," (%s)",val);
  81.         curval = bufval;
  82.     }
  83.     char buf[200];
  84.     sprintf (buf,"Configure the %s%s",keyw,curval);
  85.     return strdup (buf);
  86. }
  87.  
  88. int xconf_edit()
  89. {
  90.     /* #Specification: xconf / introduction
  91.         xconf is an interactive configurator for XFree86. It
  92.         reads and produces Xconfig files. xconf does not do any
  93.         fancy mathematics. It is just a browser allowing the user
  94.         to pick configuration option from a database of working
  95.         setup, mostly extracted from modeDB.txt maintain by
  96.         David Wexelblat [dwex@mtgzfs3.att.com].
  97.  
  98.         It allows you to pick configuration options related to the
  99.         adaptor, the monitor and the mouse. For the mouse, it tries
  100.         to be smarter probing around to identify the mouse since
  101.         the users hardly know what is the clone mouse they have.
  102.     */
  103.     /* Specification: menu / principal
  104.         The user must select one of these choice
  105.  
  106.             configure the mouse
  107.             configure the screen
  108.             configure the adaptor
  109.             quit
  110.     */
  111.     XCONFIGS xcfgs;
  112.     int done = 0;
  113.     int choice = 0;
  114.     while (!done){
  115.         static char Adaptor[] = "Adaptor";
  116.         static char Screen[] = "Screen";
  117.         static char Mouse[] = "Mouse";
  118.         static char Keyboard[]="Keyboard";
  119.         static char Fonts[]="Fonts";
  120.         static char Other[]="Other";
  121.         static char Save[]="Save";
  122.         static char Quit[]="Quit";
  123.         static char *menuopt[]={
  124.             Adaptor,    NULL,
  125.             Screen,        NULL,
  126.             Mouse,        NULL,
  127.             Keyboard,    "Configure the keyboard",
  128.             Fonts,        "Configure directories for fonts",
  129.             "-------",    "---------------------",
  130.             Other,        "other tasks ...",
  131.             Save,        "Overwrite /etc/Xconfig",
  132.             Quit,        "No save",
  133.             NULL
  134.         };
  135.         menuopt[1] = xconf_formatmenu (xcfgs.adaptor,"Adaptor");
  136.         menuopt[3] = xconf_formatmenu (xcfgs.screen,"Screen");
  137.         menuopt[5] = xconf_formatmenu (xcfgs.mouse,"Mouse");
  138.         xconf_menu ("The X configurator"
  139.             ,"This programs allows you to do the following things\n"
  140.              "      bla\n"
  141.              "      bla"
  142.             ,menuopt,choice);
  143.         free (menuopt[1]);
  144.         free (menuopt[3]);
  145.         free (menuopt[5]);
  146.         if (choice == -1){
  147.             done = 1;
  148.             break;
  149.         }else{
  150.             const char *key = menuopt[choice*2];
  151.             if (key == Adaptor){
  152.                 xconf_adaptor (xcfgs.adaptor);
  153.             }else if (key == Screen){
  154.                 xconf_screen (xcfgs.screen);
  155.             }else if (key == Mouse){
  156.                 xconf_mouse (xcfgs.mouse);
  157.             }else if (key == Keyboard){
  158.                 //xconf_keyboard (xcfgs.keyboard);
  159.             }else if (key == Fonts){
  160.                 //xconf_fonts (xcfgs.fonts);
  161.             }else if (key == Other){
  162.                 xconf_other();
  163.             }else if (key == Save){
  164.                 // Save
  165.                 XCONFIG xcfg;
  166.                 xcfg.merge (&xcfgs.fonts);
  167.                 xcfg.merge (&xcfgs.keyboard);
  168.                 xcfg.merge (&xcfgs.mouse);
  169.                 xcfg.merge (&xcfgs.screen);
  170.                 xcfg.merge (&xcfgs.adaptor);
  171.                 xcfg.write ("/tmp/Xconfig");
  172.                 done = 1;
  173.             }else if (key == Quit){
  174.                 done = 1;
  175.             }
  176.         }
  177.     }
  178.     xconf_end();
  179.     return 0;
  180. }
  181.  
  182. int xconf_main (int argc, char *argv[])
  183. {
  184.     return xconf_edit();
  185. }
  186.  
  187.